﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using SaleWebsite.Models;
using SaleWebsite.library;

namespace sale.Models
{
    public class Image
    {
        public string Name{get;set;}
        public string Images{get;set;}
        public ulong Id{get;set;}

        public static DataSet GetAll()
        {
            return MySqlImplement.GetInstance().GetQuery("image_getall");
        }
        public ulong Insert()
        {

            try
            {
                return MySqlImplement.GetInstance().ExcuteQuery(Params.GetAllParams(this), "image_insert");
            }
            catch (System.Exception ex)
            {
                throw ex;
            }

        }
        private static Image Convert_one(DataRow row)
        {
            return new Image()

            {
                Name = row["name"].ToString(),
                Id = ulong.Parse(row["id"].ToString()),
                Images = row["image"].ToString()
                

            };
        }
        public static IEnumerable<Image> ConvertAll(DataSet data)
        {
            foreach (DataRow row in data.Tables[0].Rows)
            {
                yield return Convert_one(row);
            }
        }
    }
}